﻿using System;
using System.Diagnostics;
using System.IO;

namespace Haimen;

internal class AppEnvResolver {

  public AppEnvPath Resolve(EntryArgResult args) {
    if (args.IsProd) {
      return MakeProdEnv(args.WorkingDir, args.Func);
    }

    string workingDir = args.WorkingDir;
    Console.WriteLine("-开发模式- " + workingDir);

    string resDir = DirPath(workingDir, "resources");
    string inDir = DirPath(@"E:\work_etc\nina\2023haimen2\workshop_cslab\输O入func2b\输O入");
    string outDir = DirPath(@"E:\work_etc\nina\2023haimen2\workshop_cslab\输Q出f2");

    return new(resDir, inDir, outDir);
  }

  AppEnvPath MakeProdEnv(string workingDir, string func) {
    string? binDir = Path.GetDirectoryName(workingDir);
    string inDir = DirPath(binDir, func, "输O入");
    string outDir = DirPath(binDir, func, "输Q出");

    string resDir = DirPath(workingDir, "resources");
    return new(resDir, inDir, outDir);
  }

  string DirPath(params string?[] paths) {
    string result = Path.Join(paths);
    Debug.Assert(Directory.Exists(result));
    return result;
  }
}

internal record AppEnvPath(string Res, string InStr, string Out) {
  public string ResFunc1(string path) => Path.Join(Res, "func1", path);
  public string Merge => "数据源gen.xlsx";
  public string ResFunc2(string path) => Path.Join(Res, "func2", path);

  public string In() => InStr;
  public string In(string path) => Path.Join(InStr, path);
  public string InDev(string path) => Path.Join(InStr, "dev", path);

  public string OutDir(string path) => Path.Join(Out, path);
}
//internal record AppEnvInfo();
